package com.itheima.health.dao;

import com.github.pagehelper.Page;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.CheckGroup;
import com.itheima.health.pojo.Setmeal;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

import java.time.LocalDate;

import java.util.List;

/**
 * @author zhangmeng
 * @description 套餐DAO
 * @date 2019/9/26
 **/
@Mapper
public interface SetMealDao {

    /**
     * 插入
     * @param setmeal
     */
    void insert(Setmeal setmeal);

    /**
     * 插入与检查组关联关系
     * @param setmealId
     * @param checkgroupId
     */
    void insertSetMealAndCheckGroup(@Param("setmealId") Integer setmealId, @Param("checkgroupId") Integer checkgroupId);

    /**
     * 根据条件分页查询
     * @param queryString
     * @return
     */
    Page<Setmeal> selectByCondition(@Param("queryString") String queryString);

    /**
<<<<<<< HEAD
     * 获取套餐数量
     * @return
     */
    Integer selectSetmealCount();

    List<Setmeal> selectBySetmeal();

    @Select("select * from t_setmeal where id = #{id}")
    Setmeal selectById(Integer id);

    /**
     * 根据套餐id删除套餐-检查组
     *
     * @param id
     */
    @Delete("delete from t_setmeal_checkgroup where setmeal_id = #{id}")
    void delectSetmealCheckgroupBySetmealId(Integer id);

    /**
     * 更新
     *
     * @param setmeal
     */
    void update(Setmeal setmeal);

    /**
     * 根据id删除
     *
     * @param id
     */
    @Delete("delete from t_setmeal where id = #{id}")
    void delectById(Integer id);

    /**
     * 根据套餐id查询检查组
     *
     * @param id
     * @return
     */
    @Select("select * from t_checkgroup where id in (select sc.checkgroup_id from t_setmeal st join t_setmeal_checkgroup sc where st.id = sc.setmeal_id)")
    List<CheckGroup> selectCheckGroupBySetmealId(Integer id);

    /**
     * 查询全部套餐
     *
     * @return
     */
    @Select("select * from t_setmeal")
    List<Setmeal> selectAll();

}
